from django.test import TestCase
from django.test import Client
from django.urls import reverse

from . import models

# Create your tests here.


class ApiTests(TestCase):

    def test_00000_product_type_get(self):
        """
        测试 product_type 接口
        """
        client = Client()

        response = client.get(reverse('scrum:product_type'))

        self.assertEqual(response.status_code, 200)

        self.assertEqual(isinstance(response.json(), dict), True)

    def test_10000_product_type_post(self):

        client = Client()

        data = {"product_type": "研发"}

        client.post(reverse('scrum:product_type'), data=data)

        response = client.get(reverse('scrum:product_type'))

        res = response.json()

        self.assertEqual(res['resultBody'][0]['product_type'], '研发')

    
    def test_20000_product_type_detail_get(self):
        """
        测试 product_type_detail 接口
        """

        models.ProductType.objects.create(id=1, product_type = "研发")

        client = Client()

        response = client.get(reverse('scrum:product_type_detail', args=(1,)))

        self.assertEqual(response.status_code, 200)

        self.assertEqual(isinstance(response.json(), dict), True)

        self.assertEqual(response.json()['resultBody'].get('product_type'), '研发')

    def test_20001_product_type_detail_post(self):
        """
        测试 product_type_detail 更新数据
        """

        models.ProductType.objects.create(id=1, product_type = "研发")

        client = Client()

        response = client.post(reverse('scrum:product_type_detail', args=(1,)), data={"product_type": "研发部"})

        self.assertEqual(response.status_code, 200)

        self.assertEqual(isinstance(response.json(), dict), True)
        
        self.assertEqual(response.json()['resultBody'], "修改成功")


    def test_20002_product_type_detail_delete(self):
        """
        测试 product_type_detail 删除数据
        """

        models.ProductType.objects.create(id=1, product_type = "研发")

        client = Client()

        response = client.delete(reverse('scrum:product_type_detail', args=(1,)))

        self.assertEqual(response.status_code, 200)

        self.assertEqual(isinstance(response.json(), dict), True)
        
        self.assertEqual(response.json()['resultBody'], "删除成功")

    
    def test_30000_tasks_in_progress(self):
        """
        测试 tasks_in_progress 
        """

        p = models.ProductType.objects.create(id=1, product_type = "研发")

        client = Client()

        response = client.delete(reverse('scrum:tasks_in_progress'))

        self.assertEqual(response.status_code, 200)

        self.assertEqual(isinstance(response.json(), dict), True)

    
    def test_40000_product_by_type(self):
        """
        测试 product_by_type 
        """

        p = models.ProductType.objects.create(id=1, product_type = "研发")

        client = Client()

        response = client.delete(reverse('scrum:get_product_by_type', args=(1,)))

        self.assertEqual(response.status_code, 200)

        self.assertEqual(isinstance(response.json(), dict), True)


    def test_50000_product_by_type(self):
        """
        测试 product_by_type 
        """

        p = models.ProductType.objects.create(id=1, product_type = "研发")

        client = Client()

        response = client.delete(reverse('scrum:get_product_by_type', args=(1,)))

        self.assertEqual(response.status_code, 200)

        self.assertEqual(isinstance(response.json(), dict), True)

    
    def test_60000_get_product_backlog_by_product_id(self):
        """
        测试 get_product_backlog_by_product_id 
        """

        # p = models.ProductType.objects.create(id=1, product_type = "研发")

        client = Client()

        response = client.delete(reverse('scrum:get_product_backlog_by_product_id', args=(1,)))

        self.assertEqual(response.status_code, 200)

        self.assertEqual(isinstance(response.json(), dict), True)

    def test_60000_get_sprint_backlog_by_product_backlog_id(self):
        """
        测试 get_sprint_backlog_by_product_backlog_id 
        """

        # p = models.ProductType.objects.create(id=1, product_type = "研发")

        client = Client()

        response = client.delete(reverse('scrum:get_sprint_backlog_by_product_backlog_id', args=(1,)))

        self.assertEqual(response.status_code, 200)

        self.assertEqual(isinstance(response.json(), dict), True)
        










